<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UserRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'email' => 'required|unique:user',// email字段必填 验证是否唯一
            'password' => ['required','min:6','max:10'],// password 字段必填 输入长度至少6个字符 最长10个字符
        ];
    }

    /**
     * 定义错误信息
     * 
     * @return array
    */
    public function messages()
    {
        return [
            'email.required' => '用户名必填',
            'email.unique' => '该用户名已注册，请重新输入',
            'password.required' => '密码必填',
            'password.min' => '密码必须至少为 6 个字符',
            'password.max' => '密码最大长度为 10 个字符'
        ];
    }
}
